package com.example.administrator.testdagger.countdown;

import android.content.Context;
import android.os.CountDownTimer;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ProgressBar;

import com.example.administrator.testdagger.R;

/**
 * Description: 
 * ModelName:
 *
 * @author WangJQ
 *Create at:  2018/6/1 17:58
 * Company: 沈阳艾尔时代科技发展有限公司
 * Copyright: (c)2018 AIR Times Inc. All rights reserved.
 * @version 1.0
 */

public class CountDownProgress extends LinearLayout {

    private Context mContext;
    private int mMax;
    private int mProgress;

    public CountDownProgress(Context context) {
        this(context, null);
    }

    public CountDownProgress(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CountDownProgress(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        init();
    }

    ProgressBar pb;

    private void init() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.view_countdown, this);
        pb = (ProgressBar) view.findViewById(R.id.pb_1);
    }

    CountDownTimer countDownTimer = new CountDownTimer(100000000, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            mProgress+=1;
            pb.setProgress(mProgress);
            if(mProgress == 100){
                countDownTimer.cancel();
            }
            Log.d("WJQP","onTIck:"+mProgress);
            Log.d("WJQP","onTIck:--name"+this.getClass());
        }

        @Override
        public void onFinish() {

        }
    };

    public void cancel() {
        countDownTimer.cancel();
    }

    public void start() {
        countDownTimer.start();
    }

    public void setMax(int max) {
        this.mMax = max;
        pb.setMax(max);
    }

    public void setCurrProgress(int progress) {
        this.mProgress = progress;
        pb.setProgress(progress);
    }
}
